home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / e / mailinglists / amigae.0993sept.archive / 000048_crash!prg.oxfor…d.ac.uk!m88jrh_Tue, 21 Sep 93 03:06:57 PST.msg < prev    next >
Internet Message Format  |  1994-05-26  |  6KB

  1. Received: by bkhouse.cts.com (V1.16/Amiga)
  2.     id AA00000; Tue, 21 Sep 93 03:06:57 PST
  3. Received: from sun2.nsfnet-relay.ac.uk by crash.cts.com with smtp
  4.     (Smail3.1.28.1 #18) id m0of2mx-0000NmC; Tue, 21 Sep 93 01:09 PDT
  5. Received: from ecs.oxford.ac.uk (ecs.ecs) by prg.oxford.ac.uk id AA00945;
  6.           Tue, 21 Sep 93 09:08:45 +0100
  7. Received: from ecs.ox.ac.uk (booth8.ecs) by ecs.oxford.ac.uk (4.1/ecs.1) 
  8.           id AA08915; Tue, 21 Sep 93 09:10:29 BST
  9. Received: by ecs.ox.ac.uk (4.1/ecs2.0) id AA01140; Tue, 21 Sep 93 09:09:41 BST
  10. Via: uk.ac.oxford.prg; Tue, 21 Sep 1993 09:09:10 +0100
  11. Date: Tue, 21 Sep 93 09:09:41 BST
  12. Message-Id: <9309210809.AA01140@booth8.ecs.ox.ac.uk>
  13. From: m88jrh@ecs.oxford.ac.uk
  14. To: amigae@bkhouse.cts.com
  15. Subject: A little E program
  16.  
  17.  
  18.   Dear All,
  19.    
  20.   I've written a little program which someone else on this planet may find
  21. useful.  It's not very pretty but (I think) it works.  Basically, it's for
  22. people who have a version of TeX, like me, which doesn't decide what format
  23. file to use from the command name it is invoked with (like the Unix version
  24. does).  For example, if you make a hard link to 'virtex' called 'latex' the
  25. 'lplain' format file will be used.  Frustrated I set about making my TeX
  26. do the same. 
  27.   The program can be run from Workbench or the CLI (and it does different
  28. things...).  If run from the Workbench by itself it will invoke an interactive
  29. session of TeX, LaTeX or any other kind of TeX you have by looking at the
  30. name of the Workbench file.  The command names TeX and LaTeX get translated
  31. to format files 'plain' and 'lplain' respectively, any other name is taken to
  32. be the format name.
  33.   If run with arguments from the CLI or Workbench, it will investigate each
  34. file's icon (if it exists) for a 'DOTEXFMT' tooltype. This can be 'LATEX',
  35. 'TEX', or a format file name (like 'sliplain' or 'plain').  Otherwise it
  36. looks through the first 20 lines to find a line which begins '\documentstyle'
  37. or a comment '% latex' or '% tex'.  These decide the format used.  Failing
  38. all this normal TeX is run (the 'plain' format).
  39.   I use this program in conjunction with ToolManager (2.1) to have only one
  40. icon on the dock which does LaTeX or TeX according to the file.  You can also
  41. use it as the default tool for a TeX/LaTeX file.
  42.   Notice the use of the ReadArgs template 'FILE/M' to get standard arguments
  43. (like C's argv stuff) for the CLI, and the SystemTagList function to spawn
  44. asynchronous tasks.  Also, I've used StringF which Wouter omitted from the
  45. 2.1b documentation!
  46.  
  47.    Let me know if you tidy it up or fix it!
  48.  
  49. ----
  50. MODULE 'workbench/startup', 'workbench/workbench',
  51.        'icon', 'dos/dostags', 'dos/dos'
  52.  
  53. CONST NUMARGS=1024
  54.  
  55. DEF y=11
  56.  
  57. PROC main()
  58.   DEF i, wb:PTR TO wbstartup, args:PTR TO wbarg, olddir,
  59.       templ, rdargs=NIL, arglist[NUMARGS]:LIST
  60.   iconbase:=OpenLibrary('icon.library', 33)
  61.   IF wb:=wbmessage
  62.     IF iconbase=NIL
  63.       CleanUp(10)
  64.     ENDIF
  65.     args:=wb.arglist
  66.     IF wb.numargs<>1
  67.       args++
  68.       FOR i:=2 TO wb.numargs
  69.         IF args[].lock
  70.           olddir:=CurrentDir(args[].lock)
  71.           dofile(args[].name++)
  72.           CurrentDir(olddir)
  73.         ELSE
  74.           dofile(args[].name++)
  75.         ENDIF
  76.       ENDFOR
  77.     ELSE
  78.       interact(args[].name)
  79.     ENDIF
  80.   ELSE
  81.     IF iconbase=NIL
  82.       WriteF('Can''t open icon.library\n')
  83.       CleanUp(10)
  84.     ENDIF
  85.     templ:='FILE/M'
  86.     rdargs:=ReadArgs(templ,arglist,NIL)
  87.     IF rdargs
  88.       IF arglist AND (arglist:=arglist[])
  89.         WHILE arglist[]
  90.           dofile(arglist[]++)
  91.         ENDWHILE
  92.       ENDIF
  93.       FreeArgs(rdargs)
  94.     ENDIF
  95.   ENDIF
  96.   IF iconbase THEN CloseLibrary(iconbase)
  97. ENDPROC
  98.  
  99. PROC dofile(file)
  100.   DEF handle=NIL, dobj:PTR TO diskobject, fmt=NIL, 
  101.       sysline[256]:STRING, con=NIL, tool, i=0
  102.   handle:=Open(file, OLDFILE)
  103.   IF handle
  104.     IF dobj:=GetDiskObject(file)
  105.       IF tool:=FindToolType(dobj.tooltypes, 'DOTEXFMT')
  106.         LowerStr(tool)
  107.         IF StrCmp(tool, 'tex', ALL)
  108.           fmt:='plain'
  109.         ELSEIF StrCmp(tool, 'latex', ALL)
  110.           fmt:='lplain'
  111.         ELSEIF tool[]
  112.           fmt:=tool
  113.         ENDIF
  114.       ENDIF
  115.     ENDIF
  116.     IF fmt=NIL
  117.       WHILE (i++<20) AND (ReadStr(handle, sysline)<>-1)
  118.         IF StrCmp(sysline, '\\documentstyle', STRLEN)
  119.           fmt:='lplain'
  120.         ELSE
  121.           LowerStr(sysline)
  122.           IF StrCmp(sysline, '% latex', ALL)
  123.             fmt:='lplain'
  124.           ELSEIF StrCmp(sysline, '% tex', ALL)
  125.             fmt:='plain'
  126.           ENDIF
  127.         ENDIF
  128.       ENDWHILE
  129.       IF fmt=NIL
  130.         fmt:='plain'
  131.       ENDIF
  132.     ENDIF
  133.     Close(handle)
  134.     StringF(sysline, 'con:0/\d/640/94/DoTeX - \s/CLOSE/WAIT', y, file)
  135.     IF con:=Open(sysline, NEWFILE)
  136.       StringF(sysline, 'tex:bin/virtex &\s \s', fmt, file)
  137.       SystemTagList(sysline, [SYS_INPUT, NIL, SYS_OUTPUT, con,
  138.                               SYS_ASYNCH, TRUE, NIL])
  139.       y:=y+11
  140.       IF y>106 THEN y:=11
  141.     ENDIF
  142.     IF dobj THEN FreeDiskObject(dobj)
  143.   ELSEIF wbmessage=NIL
  144.     WriteF('File "\s" does not exist\n', file)
  145.   ENDIF
  146. ENDPROC
  147.  
  148. PROC interact(file)
  149.   DEF name[128]:STRING, sysline[256]:STRING, fmt, handle, pos, found
  150.   pos:=InStr(file, ':', 0)
  151.   IF pos=-1
  152.     pos:=0
  153.   ELSE
  154.     INC pos
  155.   ENDIF
  156.   WHILE (found:=InStr(file, '/', pos))<>-1
  157.     pos:=found+1
  158.   ENDWHILE
  159.   MidStr(name, file, pos, ALL)
  160.   StringF(sysline, 'CON:0/11/640/94/DoTeX -- \s running/CLOSE/WAIT', name)
  161.   IF handle:=Open(sysline, NEWFILE)
  162.     LowerStr(name)
  163.     IF StrCmp(name, 'latex', ALL)
  164.       fmt:='lplain'
  165.     ELSEIF StrCmp(name, 'tex', ALL)
  166.       fmt:='plain'
  167.     ELSE
  168.       fmt:=name
  169.     ENDIF
  170.     StringF(sysline, 'tex:bin/virtex &\s', fmt)
  171.     SystemTagList(sysline, [SYS_INPUT, handle, SYS_OUTPUT, handle,
  172.                             SYS_ASYNCH, FALSE, NIL])
  173.     Close(handle)
  174.   ENDIF
  175. ENDPROC
  176.  
  177.  
  178. -----
  179.    _____  _
  180.      /   / |    /  /
  181.     /   /__/   /__/      Jason R. Hulance
  182.    /   /\     /  /   <m88jrh@uk.ac.oxford.ecs>
  183. |_/ . /  \ . /  / .